<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<form action="">
    <input type="text" placeholder="用户名" />
    <input type="text" placeholder="密码" />
    <input type="submit" value="注册"/>
</form>
<script>
    var inps = document.querySelectorAll("input");
    document.forms[0].onsubmit = function(e){
        e.preventDefault();
         var xhr = new XMLHttpRequest();
        xhr.open("post","/zhuce");
        xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        var u = inps[0].value;
        var p = inps[1].value;
        xhr.send(`username=${u}&password=${p}`); 
        xhr.onreadystatechange = function(){
            if(xhr.readyState === 4){
                console.log(xhr.responseText);
            }
        }
    }
</script>
</body>
</html>